package com.gwd.task.repository;

import com.gwd.task.entity.AttachmentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/12/14 10:52
 */
@Repository
public interface AttachmentRepository extends JpaRepository<AttachmentEntity, Long> {
    List<AttachmentEntity> findByCode(String code);
    AttachmentEntity findByFileName(String fileName);
    List<AttachmentEntity> findByTempCode(String tempCode);
    List<AttachmentEntity> findByCodeIn(List<String> codes);
    List<AttachmentEntity> findByFileNameIn(List<String> names);

    @Modifying
    @Transactional
    @Query(value = "update AttachmentEntity u set u.code = ?1 where u.fileName in ?2")
    void bindCode(String code, List<String> names);

    @Modifying
    @Transactional
    void deleteByIdIn(List<Long> ides);
}
